package com.wn.ziroom.config;

import com.github.pagehelper.PageHelper;
import com.rabbitmq.client.AMQP;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;
//
//@Configuration
public class RabbitMqConfig {

    private static final String NORMAL_QUEUE = "room_normal_queue";

    private static final String DEAD_QUEUE = "room_dead_queue";

    private static final String NORMAL_EXCHANGE = "room_normal_exchange";

    private static final String DEAD_EXCHANGE = "room_dead_exchange";

    private static final String NORMAL_ROUTING_KEY = "room_normal_routing_key";

    private static final String DEAD_ROUTING_KEY = "room_dead_routing_key";

    @Bean
    public Queue normalQueue() {
        Map<String, Object> args = new HashMap<>();
        args.put("x-dead-letter-exchange", DEAD_EXCHANGE);
        args.put("x-dead-letter-routing-key",DEAD_ROUTING_KEY);
        return new Queue(NORMAL_QUEUE, true, false, false, args);
    }

    @Bean
    public DirectExchange normalExchange() {
        return new DirectExchange(NORMAL_EXCHANGE, true, false);
    }

    @Bean
    public DirectExchange deadExchange() {
        return new DirectExchange(DEAD_EXCHANGE, true, false);
    }

    @Bean
    public Queue deadQueue(){
      return new Queue(DEAD_QUEUE);
    }


    @Bean
    public Binding normalBinding(@Qualifier("normalQueue") Queue queue,@Qualifier("normalExchange") DirectExchange exchange){
         return BindingBuilder.bind(queue).to(exchange).with(NORMAL_ROUTING_KEY);

    }


    @Bean
    public Binding deadBinding(@Qualifier("deadQueue") Queue queue,@Qualifier("deadExchange") DirectExchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with(DEAD_ROUTING_KEY);

    }


}
